home *** CD-ROM | disk | FTP | other *** search
- /*
- * fixasc.c
- *
- * Fixes map ascii database redundancies
- */
-
- #include <stdio.h>
- #include <stdlib.h>
-
- #define LINESIZE 80
-
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- FILE *fpi, *fpo;
- int flag, deletions = 0, passes = 0;
- char line1[80], line2[80];
-
- do {
- passes++;
- printf("Pass : %d\n", passes);
-
- if ((fpi = fopen(argv[1], "r")) == (FILE *)NULL) {
- printf("\007Error: Can't locate Database '%s'\n", argv[1]);
- exit(1);
- }
-
- if ((fpo = fopen("tmpdb", "w")) == (FILE *)NULL) {
- printf("\007Error: Can't create temporary Database\n");
- exit(1);
- }
-
- flag = 0;
-
- for (;;) {
- if (fgets(line1, LINESIZE, fpi) == NULL)
- break;
-
- if ((line1[0] == '#') || (line1[0] == '\0')) {
- fputs(line1, fpo);
- continue;
- }
-
- if (fgets(line2, LINESIZE, fpi) == NULL)
- break;
-
- if ((line2[0] == '#') || (line2[0] == '\0')) {
- fputs(line1, fpo);
- fputs(line2, fpo);
- continue;
- }
-
- if (strcmp(line1, line2) == 0) {
- fputs(line1, fpo);
- deletions++;
- flag = 1;
- }
- else {
- fputs(line1, fpo);
- fputs(line2, fpo);
- }
- }
-
- fclose(fpi);
- fclose(fpo);
-
- unlink(argv[1]);
- rename("tmpdb", argv[1]);
- } while (flag == 1);
-
- printf("\nThere were %d deletions in %d passes\n", deletions, passes);
- exit(0);
- }
-
- /* EOF */